package com.tanhua.app.interceptor;

import com.tanhua.model.pojo.User;

public class UserHolder {
    private static ThreadLocal<User> userThreadLocal = new ThreadLocal<User>();

    //保存数据到线程
    public static void set(User user){
        userThreadLocal.set(user);
    }

    //获取线程中的用户信息
    public static User get() {
        return userThreadLocal.get();
    }

    //从当前线程中获取用户id
    public static Long getUserId(){
        return userThreadLocal.get().getId();
    }

    //从当前线程中获取用户对象的手机号码
    public static String getMobile(){
        return userThreadLocal.get().getMobile();
    }

    //移除线程中的数据
    public static void remove(){
        userThreadLocal.remove();
    }
}
